﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZedGraph;


namespace TSTreeThesis.UI
{
    public partial class DataGraphForm : Form
    {
        
        private PointPairList list;
        public DataGraphForm()
        {
            InitializeComponent();
        }


        public Panel GetPanel()
        {
            return panel1;
        }

        public void SetData(PointPairList list)
        {
            this.list = list;
            zedOriginalGraph.GraphPane.CurveList.Clear();
            addLine(zedOriginalGraph, "Data", list, Color.Red, SymbolType.None, 1, "Original Data Set");
        }

        public void ReDrawData()
        {
            addLine(zedOriginalGraph, "Data", list, Color.Red, SymbolType.None, 1, "Original Data Set");
        }

        private void addLine(ZedGraphControl zgc, string name, PointPairList dataList, Color color, SymbolType s, int width, string filename)
        {
            GraphPane myPane = zgc.GraphPane;
            LineItem myCurve = myPane.AddCurve(name, dataList, color, s);
            myCurve.Line.Width = width;
            myPane.Title.Text = filename;
            myPane.XAxis.Title.Text = "Times";
            myPane.YAxis.Title.Text = "Values";
            zgc.AxisChange();
            zgc.Refresh();
        }

        public void DrawQueryResult(double[] result, int index, int offset)
        {
            if (result == null) return;

            GraphPane myPane = zedOriginalGraph.GraphPane;

            PointPairList list = new PointPairList();
            for (int i = 0; i < result.Length; i++)
            {
                double p = result[i] - offset;
                list.Add(i + index, p);
            }

            LineItem myCurve = myPane.AddCurve("", list, Color.Blue, SymbolType.None);
            myCurve.Line.Width = 1;
        }

        public void ClearQueryResult()
        {
            SetData(list);
        }

        public void ClearData()
        {
            zedOriginalGraph.GraphPane.CurveList.Clear();
        }

        public void Refresh()
        {
            zedOriginalGraph.AxisChange();
            zedOriginalGraph.Refresh();
        }
    }
}
